//
//  UIViewExtension.swift
//  Bee
//
//  Created by zhujinhui on 15/12/30.
//  Copyright © 2015年 kyson. All rights reserved.
//

import UIKit

extension UIView {
    
    /// The top coordinate of the UIView.
    public var top: CGFloat {
        get {
            return frame.top
        }
        set(value) {
            var frame = self.frame
            frame.top = value
            self.frame = frame
        }
    }
    
    /// The left coordinate of the UIView.
    public var left: CGFloat {
        get {
            return frame.left
        }
        set(value) {
            var frame = self.frame
            frame.left = value
            self.frame = frame
        }
    }
    
    /// The bottom coordinate of the UIView.
    public var bottom: CGFloat {
        get {
            return frame.bottom
        }
        set(value) {
            var frame = self.frame
            frame.bottom = value
            self.frame = frame
        }
    }
    
    /// The right coordinate of the UIView.
    public var right: CGFloat {
        get {
            return frame.right
        }
        set(value) {
            var frame = self.frame
            frame.right = value
            self.frame = frame
        }
    }
    
    // The width of the UIView.
    public var width: CGFloat {
        get {
            return frame.width
        }
        set(value) {
            var frame = self.frame
            var size = frame.size
            size.width = value
            frame.size = size
            self.frame = frame
        }
    }
    
    // The height of the UIView.
    public var height: CGFloat {
        get {
            return frame.height
        }
        set(value) {
            var frame = self.frame
            var size = frame.size
            size.height = value
            frame.size = size
            self.frame = frame
        }
    }
    
    /// The horizontal center coordinate of the UIView.
    public var centerX: CGFloat {
        get {
            return frame.centerX
        }
        set(value) {
            var frame = self.frame
            frame.centerX = value
            self.frame = frame
        }
    }
    
    /// The vertical center coordinate of the UIView.
    public var centerY: CGFloat {
        get {
            return frame.centerY
        }
        set(value) {
            var frame = self.frame
            frame.centerY = value
            self.frame = frame
        }
    }
    
    /// The vertical center coordinate of the UIView.
    public func addBottomLine()->UIView {
        let px1 = 1/UIScreen.mainScreen().scale
        let lineView = UIView.init(frame: CGRectMake(0, self.height - px1, self.width, px1))
        lineView.backgroundColor = UIColor.init(hex6: 0xd3d4d4)
        self.addSubview(lineView)
        return lineView
    }
    
    public func addTopLine()->UIView {
        let px1 = 1/UIScreen.mainScreen().scale
        let lineView = UIView.init(frame: CGRectMake(0, 0, self.width, px1))
        lineView.backgroundColor = UIColor.init(hex6: 0xd3d4d4)
        self.addSubview(lineView)
        return lineView
    }
}
